package stu.day39_day.day40;

import java.util.Arrays;

public class hw5 {

    public int bestTeamScore(int[] scores, int[] ages) {
        int len = scores.length;
        int[][] arr = new int[len][2];
        for (int i = 0; i < len; i++) {
            arr[i][0] = scores[i];
            arr[i][1] = ages[i];
        }
        Arrays.sort(arr,(a, b)-> a[1]==b[1]?a[0]-b[0]:a[1]-b[1] );
        return dp(arr);
    }

    public static int dp(int[][] arr){
        int len =arr.length;
        int[] dp = new int[len];
        dp[0] = arr[0][0];
        int max = 0;
        for(int i=1;i<len;i++){
            for(int j=0;j<i;j++){
                if(arr[i][0]>=arr[j][0]){
                    dp[i] = Math.max(dp[i],dp[j]+arr[i][0]);
                }
            }
            dp[i] = Math.max(dp[i],arr[i][0]);
        }
        return Arrays.stream(dp).max().getAsInt();
    }

}
